<?php

namespace app\admin\logic;
use think\Model;
class Menus extends Model{
 //  $menu = array(
//           'id'=>菜单id,
//           'name'=>菜单名称,
//           'active'=>是否激活,
//           "controller"=>操作
//           "sub"=>子菜单
//       );
    public function makeMenus($fid,$sid,$leave){
        $menu = array();
        $i=0;
        $menus = \think\Db::table('menu')->where('display',1)->where('leave','egt',(int)$leave)->order('id')->select();
        foreach ($menus as $v){
            if($v["fid"]===0){
                $menu[$v["id"]-1] = $this->OpMenus($v, $fid, $sid); 
                $i++;
            }else{
                $menu[$v["fid"]-1]["sub"][] = $this->OpMenus($v, $fid, $sid);
            }
            
        }
       return $menu;
    }
    
    public function OpMenus($v,$fid,$sid){
       $menu = array();
       
       $menu["id"] = $v["id"];
       $menu["name"] = $v["name"];
       if($v["id"] === $fid){
           $menu["active"] = "nav-active";
       }else if($v["id"] === $sid){
           $menu["active"] = "active";
       }else{
            $menu["active"] = "";
       }
       $menu["controller"]=$v["controller"];
        return $menu;
    }
    
    
}
